home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 May: Tool Chest / Developer CD Series May 1996 (Tool Chest) (Apple Computer) (1996).iso / Sample Code / Snippets / QuickDraw / Imageer 1.0.0d3 / source / gxGraphics.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-16  |  21.4 KB  |  655 lines  |  [TEXT/MPS ]

  1. /****************************************************/
  2. /*                                                    */
  3. /*    File:        gxGraphics.c                        */
  4. /*                                                    */
  5. /*    Program:    Imageer                                */
  6. /*                                                    */
  7. /*    By:            Jason Hodges-Harris                    */
  8. /*                                                    */
  9. /*    Created:    26/10/95  00:00:00 AM                */
  10. /*                                                    */
  11. /*    Version:    1.0.0d3                                */
  12. /*                                                    */
  13. /*    Copyright:    © 1995-96 Apple Computer, Inc.,        */ 
  14. /*                    all rights reserved.            */        
  15. /*                                                    */
  16. /****************************************************/
  17.  
  18.  
  19. /**** Macintosh Toolbox Headers *****/
  20.  
  21. #ifndef __GXENVIRONMENT__
  22. #include <GXEnvironment.h>
  23. #endif
  24.  
  25. #ifndef __GXGRAPHICS__
  26. #include <GXGraphics.h>
  27. #endif
  28.  
  29. #ifndef __GXTYPES__
  30. #include <GXTypes.h>
  31. #endif
  32.  
  33. #ifndef __QDOFFSCREEN__
  34. #include <QDOffscreen.h>
  35. #endif
  36.  
  37. #ifndef __TYPES__
  38. #include <Types.h>
  39. #endif
  40.  
  41.  
  42. /****   Application headers and prototypes   ****/
  43.  
  44. #ifndef __IMAGEERAPPHEADER__
  45. #include "Imageer.app.h"
  46. #endif
  47.  
  48. #ifndef __IMAGEERPROTOSHEADER__
  49. #include "Imageer.protos.h"
  50. #endif
  51.  
  52.  
  53. /****    Function to convert an existing Color QuickDraw image to a QuickDraw GX object    ****/
  54.  
  55. #pragma segment gxGrafix
  56. OSErr ConvPixMapToGXShape(ImageDocHndl theDocHndl, WindowPtr theWindow)
  57. {
  58.     ImageDocPtr         theDocPtr;
  59.     PixMapHandle        thePixMapHndl = nil;
  60.     gxShapeSpoolUPP        theGXSpoolUPP;
  61.     GDHandle            theGDevHndl = nil;
  62.     GWorldPtr            oldPort;
  63.     Rect                theImagePortRect = (*theDocHndl)->theImageWorld->portRect;
  64.     OSErr                error = noErr;
  65.     Point                scale = {1,1};
  66.     
  67.     GetGWorld(&oldPort,&theGDevHndl);
  68.     thePixMapHndl = GetGWorldPixMap((*theDocHndl)->theImageWorld);
  69.     if (PixMap32Bit(thePixMapHndl))
  70.         SaveSetMMUMode(true);
  71.     if (!LockPixels(thePixMapHndl))
  72.         error = kFailedLockPixels;
  73.     if (!error)
  74.     {
  75.         HLock((Handle)theDocHndl);
  76.         theDocPtr = *theDocHndl;
  77.         // Convert QuickDraw GWorld to GX based shape object
  78.         theGXSpoolUPP = NewgxShapeSpoolProc(QDShapeSpooler);
  79.         SetGWorld(theDocPtr->theImageWorld,nil);
  80.         GXInstallQDTranslator((GrafPtr)theDocPtr->theImageWorld, gxDefaultOptionsTranslation,
  81.                               &theImagePortRect,
  82.                               &theImagePortRect,
  83.                               scale, theGXSpoolUPP, (void*)theDocPtr);
  84.         CopyBits((BitMap*)(*thePixMapHndl),
  85.                  (BitMap*)(*thePixMapHndl),
  86.                  &theImagePortRect,
  87.                  &theImagePortRect,srcCopy,nil);
  88.         GXRemoveQDTranslator((GrafPtr)theDocPtr->theImageWorld,nil);
  89.         DisposeRoutineDescriptor((UniversalProcPtr)theGXSpoolUPP);
  90.     }
  91.     UnlockPixels(thePixMapHndl);            // unlock GWorld
  92.     SaveSetMMUMode(false);
  93.     SetGWorld((CGrafPtr)theWindow,theGDevHndl);
  94.     InitTransferMatrix (theDocHndl,gxCopyMode,gxCopyMode,gxCopyMode);        // init transfer matrix for shape
  95.     GXSetShapeInk(theDocPtr->theGXImageShape, theDocPtr->theInkShape);
  96.     HUnlock((Handle)theDocHndl);
  97.     InvalRect(&theWindow->portRect);        // invalidate window port rect
  98.     SetGWorld(oldPort,theGDevHndl);
  99.     return error;
  100. }
  101.  
  102.  
  103. /****    spooler function for Color QuickDraw to QuickDRaw GX translator *****/
  104.  
  105. #pragma segment gxGrafix
  106. OSErr QDShapeSpooler (gxShape theShape, void *theDocHndlRef)
  107. {
  108.     ImageDocPtr theDocPtr = (ImageDocPtr)theDocHndlRef;
  109.     
  110.     theDocPtr->theGXImageShape = GXCopyToShape(nil, theShape);
  111.     GXSetShapeViewPorts(theDocPtr->theGXImageShape,1,&(theDocPtr->theGxChildView));
  112.     return    (GXGetGraphicsError(nil));
  113. }
  114.  
  115.  
  116. /****    Create GX View Ports for a given window    ****/
  117.  
  118. #pragma segment gxGrafix
  119. OSErr    CreateGXviewPorts(ImageDocHndl theDocHndl, WindowPtr theWindow)
  120. {
  121.     gxRectangle        theViewRect;
  122.     gxShape            theContentShape;
  123.     Rect            thePortRect;
  124.     OSErr            error = noErr;
  125.     
  126.     // Create GX parent viewport
  127.     thePortRect = (*theDocHndl)->theImageWorld->portRect;
  128.     CreateGXRect(&theViewRect, thePortRect.top, thePortRect.left,
  129.                 thePortRect.bottom, thePortRect.right);
  130.     theContentShape = GXNewRectangle(&theViewRect);
  131.     (**theDocHndl).theGXview = GXNewWindowViewPort(theWindow);
  132.     GXSetViewPortClip((**theDocHndl).theGXview, theContentShape);
  133.     GXDisposeShape (theContentShape);
  134.     // Create GX child viewport
  135.     thePortRect = theWindow->portRect;
  136.     CreateGXRect(&theViewRect, thePortRect.top, thePortRect.left,
  137.                 thePortRect.bottom- kScrollBarWidth, thePortRect.right- kScrollBarWidth);
  138.     (**theDocHndl).theGxChildView = 
  139.         GXNewViewPort(GXGetViewPortViewGroup((**theDocHndl).theGXview));
  140.     theContentShape = GXNewRectangle(&theViewRect);
  141.     GXSetViewPortClip((**theDocHndl).theGxChildView, theContentShape);
  142.     GXSetViewPortMapping((**theDocHndl).theGxChildView, nil);
  143.     GXSetViewPortParent((**theDocHndl).theGxChildView, (**theDocHndl).theGXview);
  144.     GXDisposeShape (theContentShape);
  145.     return error;
  146. }
  147.  
  148.  
  149. /****    Update QDGX Object displayed in child viewport    ****/
  150.  
  151. #pragma segment gxGrafix
  152. void    UpdateGXObjectDisplay(ImageDocHndl    theWindDocHndl, WindowPtr theWindow)
  153. {
  154.     gxShape            theContentShape;
  155.     gxRectangle        theViewRect;
  156.     Rect            thePortRect;
  157.     short            theXvalue,
  158.                     theYvalue;
  159.  
  160.     theXvalue = GetControlValue((**theWindDocHndl).theHScrollBar);
  161.     theYvalue = GetControlValue((**theWindDocHndl).theVScrollBar);
  162.     GXMoveShapeTo((**theWindDocHndl).theGXImageShape,ff(-theXvalue), ff(-theYvalue));
  163.     thePortRect = theWindow->portRect;
  164.     CreateGXRect(&theViewRect, thePortRect.top, thePortRect.left,
  165.                 thePortRect.bottom- kScrollBarWidth, thePortRect.right- kScrollBarWidth);
  166.     theContentShape = GXNewRectangle(&theViewRect);
  167.     GXSetViewPortClip((**theWindDocHndl).theGxChildView, theContentShape);
  168.     GXDisposeShape (theContentShape);
  169.     GXDrawShape((**theWindDocHndl).theGXImageShape);
  170. }
  171.  
  172.  
  173. /****    Initialise transfer matrix    ****/
  174.  
  175. #pragma segment gxGrafix
  176. void    InitTransferMatrix (ImageDocHndl theDocHndl,
  177.                             gxComponentMode comp1TransferMode,
  178.                             gxComponentMode comp2TransferMode,
  179.                             gxComponentMode comp3TransferMode)
  180. {
  181.     gxTransferMode    theTransferMode;
  182.     short counter;
  183.  
  184.     theTransferMode.space = gxRGBSpace;
  185.     theTransferMode.set = nil;
  186.     theTransferMode.profile = nil;
  187.  
  188.  
  189.     // initialise source matrix tranfer mode
  190.     theTransferMode.sourceMatrix[0][0] = ff(1.0);
  191.     for (counter = 1;counter<4;counter++)
  192.         theTransferMode.sourceMatrix[0][counter] = 0;
  193.     theTransferMode.sourceMatrix[1][0] = 0;
  194.     theTransferMode.sourceMatrix[1][1] = ff(1.0);
  195.     for (counter = 2;counter<4;counter++)
  196.         theTransferMode.sourceMatrix[1][counter] = 0;
  197.     for (counter = 0;counter<2;counter++)
  198.         theTransferMode.sourceMatrix[2][counter] = 0;
  199.     theTransferMode.sourceMatrix[2][2] = ff(1.0);
  200.     theTransferMode.sourceMatrix[2][3] = 0;
  201.     for (counter = 0;counter<3;counter++)
  202.         theTransferMode.sourceMatrix[3][counter] = 0;
  203.     theTransferMode.sourceMatrix[3][3] = ff(1.0);
  204.     for (counter = 0;counter<4;counter++)
  205.         theTransferMode.sourceMatrix[4][counter] = 0;
  206.  
  207.     // initialise device matrix tranfer mode
  208.     theTransferMode.deviceMatrix[0][0] = ff(1.0);
  209.     for (counter = 1;counter<4;counter++)
  210.         theTransferMode.deviceMatrix[0][counter] = 0;
  211.     theTransferMode.deviceMatrix[1][0] = 0;
  212.     theTransferMode.deviceMatrix[1][1] = ff(1.0);
  213.     for (counter = 2;counter<4;counter++)
  214.         theTransferMode.deviceMatrix[1][counter] = 0;
  215.     for (counter = 0;counter<2;counter++)
  216.         theTransferMode.deviceMatrix[2][counter] = 0;
  217.     theTransferMode.deviceMatrix[2][2] = ff(1.0);
  218.     theTransferMode.deviceMatrix[2][3] = 0;
  219.     for (counter = 0;counter<3;counter++)
  220.         theTransferMode.deviceMatrix[3][counter] = 0;
  221.     theTransferMode.deviceMatrix[3][3] = ff(1.0);
  222.     for (counter = 0;counter<4;counter++)
  223.         theTransferMode.deviceMatrix[4][counter] = 0;
  224.  
  225.     // initialise result matrix tranfer mode
  226.     theTransferMode.resultMatrix[0][0] = ff(1.0);
  227.     for (counter = 1;counter<4;counter++)
  228.         theTransferMode.resultMatrix[0][counter] = 0;
  229.     theTransferMode.resultMatrix[1][0] = 0;
  230.     theTransferMode.resultMatrix[1][1] = ff(1.0);
  231.     for (counter = 2;counter<4;counter++)
  232.         theTransferMode.resultMatrix[1][counter] = 0;
  233.     for (counter = 0;counter<2;counter++)
  234.         theTransferMode.resultMatrix[2][counter] = 0;
  235.     theTransferMode.resultMatrix[2][2] = ff(1.0);
  236.     theTransferMode.resultMatrix[2][3] = 0;
  237.     for (counter = 0;counter<3;counter++)
  238.         theTransferMode.resultMatrix[3][counter] = 0;
  239.     theTransferMode.resultMatrix[3][3] = ff(1.0);
  240.     for (counter = 0;counter<4;counter++)
  241.         theTransferMode.resultMatrix[4][counter] = 0;
  242.  
  243.     theTransferMode.flags = 0;
  244.     // Red Component
  245.     theTransferMode.component[0].mode                = comp1TransferMode;
  246.     theTransferMode.component[0].flags                = 0;
  247.     theTransferMode.component[0].sourceMinimum        = 0;
  248.     theTransferMode.component[0].deviceMinimum        = 0;
  249.     theTransferMode.component[0].clampMinimum        = 0;
  250.     theTransferMode.component[0].clampMaximum        = gxColorValue1;
  251.     theTransferMode.component[0].sourceMaximum        = gxColorValue1;
  252.     theTransferMode.component[0].deviceMaximum        = gxColorValue1;
  253.     // Green Component
  254.     theTransferMode.component[1].mode                = comp2TransferMode;
  255.     theTransferMode.component[1].flags                = 0;
  256.     theTransferMode.component[1].sourceMinimum        = 0;
  257.     theTransferMode.component[1].deviceMinimum        = 0;
  258.     theTransferMode.component[1].clampMinimum        = 0;
  259.     theTransferMode.component[1].clampMaximum        = gxColorValue1;
  260.     theTransferMode.component[1].sourceMaximum        = gxColorValue1;
  261.     theTransferMode.component[1].deviceMaximum        = gxColorValue1;
  262.     // Blue Component
  263.     theTransferMode.component[2].mode                = comp3TransferMode;
  264.     theTransferMode.component[2].flags                = 0;
  265.     theTransferMode.component[2].sourceMinimum        = 0;
  266.     theTransferMode.component[2].deviceMinimum        = 0;
  267.     theTransferMode.component[2].clampMinimum        = 0;
  268.     theTransferMode.component[2].clampMaximum        = gxColorValue1;
  269.     theTransferMode.component[2].sourceMaximum        = gxColorValue1;
  270.     theTransferMode.component[2].deviceMaximum        = gxColorValue1;
  271.     (**theDocHndl).theInkShape                        = GXNewInk();
  272.     GXSetInkTransfer((**theDocHndl).theInkShape, &theTransferMode);
  273. }
  274.  
  275.  
  276. /****    gxShape rotation function    ****/
  277.  
  278. #pragma segment gxGrafix
  279. OSErr RotateGxShape(ImageDocHndl theDocHndl, WindowPtr theWindow, Fixed angle)
  280. {
  281.     GDHandle            theGDevHndl = nil;
  282.     GWorldPtr            oldPort;
  283.     gxTransform            theShapeTransform,
  284.                         theTempTransform;
  285.     gxMapping            theTransMapping;
  286.     gxPoint                theImageCentre;
  287.     OSErr                error = noErr;
  288.     
  289.     GetGWorld(&oldPort,&theGDevHndl);
  290.     theShapeTransform = GXGetShapeTransform((**theDocHndl).theGXImageShape);
  291.     theTempTransform = GXNewTransform();
  292.     GXGetShapeCenter((**theDocHndl).theGXImageShape,0,&theImageCentre);
  293.     GXRotateTransform(theTempTransform,angle,theImageCentre.x,theImageCentre.y);
  294.     GXGetTransformMapping(theTempTransform,&theTransMapping);
  295.     GXMapTransform(theShapeTransform,&theTransMapping);
  296.     GXDisposeTransform(theTempTransform);
  297.     GXSetShapeTransform((**theDocHndl).theGXImageShape, theShapeTransform);
  298.     GXSetShapeAttributes((**theDocHndl).theGXImageShape, gxNoAttributes);
  299.     SetGWorld((CGrafPtr)theWindow,theGDevHndl);
  300.     InvalRect(&theWindow->portRect);        // invalidate window port rect
  301.     SetGWorld(oldPort,theGDevHndl);
  302.     return error;
  303. }
  304.  
  305.  
  306. /****    gxShape Mirror image transform    ****/
  307.  
  308. #pragma segment gxGrafix
  309. OSErr MirrorGxShape(ImageDocHndl theDocHndl, WindowPtr theWindow, Boolean isXaxis)
  310. {
  311.     GDHandle            theGDevHndl = nil;
  312.     GWorldPtr            oldPort;
  313.     gxTransform            theShapeTransform;
  314.     gxMapping            theTransMapping;
  315.     gxRectangle            theShapeBounds;
  316.     gxPoint                theImageCentre;
  317.     OSErr                error = noErr;
  318.     
  319.     GetGWorld(&oldPort,&theGDevHndl);
  320.     theShapeTransform = GXGetShapeTransform((**theDocHndl).theGXImageShape);
  321.     GXGetShapeCenter((**theDocHndl).theGXImageShape,0,&theImageCentre);
  322.     /****    Identity transform matrix elements    ****/
  323.     theTransMapping.map[1][0] = 0;
  324.     theTransMapping.map[2][0] = 0;
  325.     theTransMapping.map[0][1] = 0;
  326.     theTransMapping.map[2][1] = 0;
  327.     theTransMapping.map[0][2] = 0;
  328.     theTransMapping.map[1][2] = 0;
  329.     theTransMapping.map[2][2] = fract1;
  330.     if (isXaxis)        // mirror shape along X axis
  331.     {
  332.         theTransMapping.map[0][0] = ff(1);
  333.         theTransMapping.map[1][1] = ff(-1);
  334.     }
  335.     else                // mirror shape along Y axis
  336.     {
  337.         theTransMapping.map[0][0] = ff(-1);
  338.         theTransMapping.map[1][1] = ff(1);
  339.     }
  340.     GXMapTransform(theShapeTransform,&theTransMapping);
  341.     GXSetShapeTransform((**theDocHndl).theGXImageShape, theShapeTransform);
  342.     GXSetShapeAttributes((**theDocHndl).theGXImageShape, gxMapTransformShape);
  343.     GXGetShapeBounds((**theDocHndl).theGXImageShape, 0, &theShapeBounds);
  344.     if (isXaxis)
  345.         GXMoveShape((**theDocHndl).theGXImageShape,0, theShapeBounds.bottom - theShapeBounds.top);
  346.     else
  347.         GXMoveShape((**theDocHndl).theGXImageShape,theShapeBounds.right - theShapeBounds.left, 0);    
  348.     GXSetShapeAttributes((**theDocHndl).theGXImageShape, gxNoAttributes);
  349.     SetGWorld((CGrafPtr)theWindow,theGDevHndl);
  350.     InvalRect(&theWindow->portRect);        // invalidate window port rect
  351.     SetGWorld(oldPort,theGDevHndl);
  352.     return error;
  353. }
  354.  
  355.  
  356. /****    QDGX Ink object inverter    ****/
  357.  
  358. #pragma segment gxGrafix
  359. OSErr    GxShapeInkInvert (ImageDocHndl theDocHndl, WindowPtr theWindow)
  360. {
  361.     GDHandle            theGDevHndl = nil;
  362.     GWorldPtr            oldPort;
  363.     gxTransferMode        theTransferMode;
  364.     OSErr                error = noErr;
  365.     short                counter;
  366.     
  367.     GetGWorld(&oldPort,&theGDevHndl);
  368.     GXGetInkTransfer((**theDocHndl).theInkShape, &theTransferMode);
  369.     if (&theTransferMode == nil)
  370.     {
  371.         DisplayAlert(rGenAlert,rQDGXmessages,iInkGetFail);
  372.         error = kGXFailGetInk;
  373.     }
  374.     else
  375.     {
  376.         if (theTransferMode.sourceMatrix[4][0] == ff(1.0))
  377.         {
  378.             //    Reset to color identity matrix
  379.             for (counter = 0;counter<4;counter++)
  380.             {
  381.                 theTransferMode.sourceMatrix[4][counter] = ff(0.0);
  382.                 theTransferMode.sourceMatrix[counter][counter] = ff(1.0);
  383.             }
  384.         }
  385.         else
  386.         {
  387.             //    Set to color inversion matrix
  388.             for (counter = 0;counter<4;counter++)
  389.             {
  390.                 theTransferMode.sourceMatrix[4][counter] = ff(1.0);
  391.                 theTransferMode.sourceMatrix[counter][counter] = ff(-1.0);
  392.             }
  393.         }
  394.         GXSetInkTransfer((**theDocHndl).theInkShape, &theTransferMode);
  395.         GXSetShapeInk((**theDocHndl).theGXImageShape, (**theDocHndl).theInkShape);
  396.         SetGWorld((CGrafPtr)theWindow,theGDevHndl);
  397.         InvalRect(&theWindow->portRect);        // invalidate window port rect
  398.         SetGWorld(oldPort,theGDevHndl);    
  399.     }
  400.     return error;
  401. }
  402.  
  403.  
  404. /****    Switch ink object source color component source transfer value    Removes color components ****/
  405.  
  406. #pragma segment gxGrafix
  407. OSErr    RGBColorComponent (ImageDocHndl theDocHndl, WindowPtr theWindow, short colorComponent)
  408. {
  409.     GDHandle            theGDevHndl = nil;
  410.     GWorldPtr            oldPort;
  411.     gxTransferMode        theTransferMode;
  412.     OSErr                error = noErr;
  413.     short                counter;
  414.     
  415.     GetGWorld(&oldPort,&theGDevHndl);
  416.     GXGetInkTransfer((**theDocHndl).theInkShape, &theTransferMode);
  417.     if (&theTransferMode == nil)
  418.     {
  419.         DisplayAlert(rGenAlert,rQDGXmessages,iInkGetFail);
  420.         error = kGXFailGetInk;
  421.     }
  422.     else
  423.     {
  424.         theTransferMode.space = gxRGBSpace;
  425.         theTransferMode.set = nil;
  426.         theTransferMode.profile = nil;
  427.     
  428.     
  429.         // initialise source matrix tranfer mode
  430.         theTransferMode.sourceMatrix[0][0] = ff(1.0);
  431.         for (counter = 1;counter<4;counter++)
  432.             theTransferMode.sourceMatrix[0][counter] = 0;
  433.         theTransferMode.sourceMatrix[1][0] = 0;
  434.         theTransferMode.sourceMatrix[1][1] = ff(1.0);
  435.         for (counter = 2;counter<4;counter++)
  436.             theTransferMode.sourceMatrix[1][counter] = 0;
  437.         for (counter = 0;counter<2;counter++)
  438.             theTransferMode.sourceMatrix[2][counter] = 0;
  439.         theTransferMode.sourceMatrix[2][2] = ff(1.0);
  440.         theTransferMode.sourceMatrix[2][3] = 0;
  441.         for (counter = 0;counter<3;counter++)
  442.             theTransferMode.sourceMatrix[3][counter] = 0;
  443.         theTransferMode.sourceMatrix[3][3] = ff(1.0);
  444.         for (counter = 0;counter<4;counter++)
  445.             theTransferMode.sourceMatrix[4][counter] = 0;
  446.  
  447.         // initialise device matrix tranfer mode
  448.         theTransferMode.deviceMatrix[0][0] = ff(1.0);
  449.         for (counter = 1;counter<4;counter++)
  450.             theTransferMode.deviceMatrix[0][counter] = 0;
  451.         theTransferMode.deviceMatrix[1][0] = 0;
  452.         theTransferMode.deviceMatrix[1][1] = ff(1.0);
  453.         for (counter = 2;counter<4;counter++)
  454.             theTransferMode.deviceMatrix[1][counter] = 0;
  455.         for (counter = 0;counter<2;counter++)
  456.             theTransferMode.deviceMatrix[2][counter] = 0;
  457.         theTransferMode.deviceMatrix[2][2] = ff(1.0);
  458.         theTransferMode.deviceMatrix[2][3] = 0;
  459.         for (counter = 0;counter<3;counter++)
  460.             theTransferMode.deviceMatrix[3][counter] = 0;
  461.         theTransferMode.deviceMatrix[3][3] = ff(1.0);
  462.         for (counter = 0;counter<4;counter++)
  463.             theTransferMode.deviceMatrix[4][counter] = 0;
  464.     
  465.         // initialise result matrix tranfer mode
  466.         theTransferMode.resultMatrix[0][0] = ff(1.0);
  467.         for (counter = 1;counter<4;counter++)
  468.             theTransferMode.resultMatrix[0][counter] = 0;
  469.         theTransferMode.resultMatrix[1][0] = 0;
  470.         theTransferMode.resultMatrix[1][1] = ff(1.0);
  471.         for (counter = 2;counter<4;counter++)
  472.             theTransferMode.resultMatrix[1][counter] = 0;
  473.         for (counter = 0;counter<2;counter++)
  474.             theTransferMode.resultMatrix[2][counter] = 0;
  475.         theTransferMode.resultMatrix[2][2] = ff(1.0);
  476.         theTransferMode.resultMatrix[2][3] = 0;
  477.         for (counter = 0;counter<3;counter++)
  478.             theTransferMode.resultMatrix[3][counter] = 0;
  479.         theTransferMode.resultMatrix[3][3] = ff(1.0);
  480.         for (counter = 0;counter<4;counter++)
  481.             theTransferMode.resultMatrix[4][counter] = 0;
  482.     
  483.         theTransferMode.flags = 0;
  484.         // Red Component
  485.         theTransferMode.component[0].mode                = gxCopyMode;
  486.         theTransferMode.component[0].flags                = 0;
  487.         theTransferMode.component[0].sourceMinimum        = 0;
  488.         theTransferMode.component[0].deviceMinimum        = 0;
  489.         theTransferMode.component[0].clampMinimum        = 0;
  490.         theTransferMode.component[0].sourceMaximum        = gxColorValue1;
  491.         theTransferMode.component[0].deviceMaximum        = gxColorValue1;
  492.         // Green Component
  493.         theTransferMode.component[1].mode                =  gxCopyMode;
  494.         theTransferMode.component[1].flags                = 0;
  495.         theTransferMode.component[1].sourceMinimum        = 0;
  496.         theTransferMode.component[1].deviceMinimum        = 0;
  497.         theTransferMode.component[1].clampMinimum        = 0;
  498.         theTransferMode.component[1].sourceMaximum        = gxColorValue1;
  499.         theTransferMode.component[1].deviceMaximum        = gxColorValue1;
  500.         // Blue Component
  501.         theTransferMode.component[2].mode                = gxCopyMode;
  502.         theTransferMode.component[2].flags                = 0;
  503.         theTransferMode.component[2].sourceMinimum        = 0;
  504.         theTransferMode.component[2].deviceMinimum        = 0;
  505.         theTransferMode.component[2].clampMinimum        = 0;
  506.         theTransferMode.component[2].sourceMaximum        = gxColorValue1;
  507.         theTransferMode.component[2].deviceMaximum        = gxColorValue1;
  508.         switch (colorComponent)
  509.         {
  510.             case kRedComp:
  511.                 theTransferMode.component[0].clampMaximum = 
  512.                     (theTransferMode.component[0].clampMaximum == 0)    ? gxColorValue1 : 0;
  513.             break;
  514.             case kGreenComp:
  515.                 theTransferMode.component[1].clampMaximum = 
  516.                     (theTransferMode.component[1].clampMaximum == 0)    ? gxColorValue1 : 0;
  517.             break;
  518.             case kBlueComp:
  519.                 theTransferMode.component[2].clampMaximum = 
  520.                     (theTransferMode.component[2].clampMaximum == 0)    ? gxColorValue1 : 0;
  521.             break;
  522.         }
  523.         GXSetInkTransfer((**theDocHndl).theInkShape, &theTransferMode);
  524.         GXSetShapeInk((**theDocHndl).theGXImageShape, (**theDocHndl).theInkShape);
  525.         SetGWorld((CGrafPtr)theWindow,theGDevHndl);
  526.         InvalRect(&theWindow->portRect);        // invalidate window port rect
  527.         SetGWorld(oldPort,theGDevHndl);
  528.  
  529.     }
  530.     return error;
  531. }
  532.  
  533.  
  534.  
  535. /****    QDGX Ink object inverter    ****/
  536.  
  537. #pragma segment gxGrafix
  538. OSErr    GxShapeInkBrightness (ImageDocHndl theDocHndl, WindowPtr theWindow, Boolean isBrighter)
  539. {
  540.     GDHandle            theGDevHndl = nil;
  541.     GWorldPtr            oldPort;
  542.     gxTransferMode        theTransferMode;
  543.     OSErr                error = noErr;
  544.     short                counter;
  545.     
  546.     GetGWorld(&oldPort,&theGDevHndl);
  547.     GXGetInkTransfer((**theDocHndl).theInkShape, &theTransferMode);
  548.     if (&theTransferMode == nil)
  549.     {
  550.         DisplayAlert(rGenAlert,rQDGXmessages,iInkGetFail);
  551.         error = kGXFailGetInk;
  552.     }
  553.     else
  554.     {
  555.         theTransferMode.space = gxRGBSpace;
  556.         theTransferMode.set = nil;
  557.         theTransferMode.profile = nil;
  558.     
  559.     
  560.         if (isBrighter)
  561.         {
  562.             for (counter = 0;counter<4;counter++)
  563.                 theTransferMode.sourceMatrix[counter][counter] += fl(0.1);
  564.         }
  565.         else
  566.         {
  567.             for (counter = 0;counter<4;counter++)
  568.                 theTransferMode.sourceMatrix[counter][counter] -= fl(0.1);
  569.         }
  570.         GXSetInkTransfer((**theDocHndl).theInkShape, &theTransferMode);
  571.         GXSetShapeInk((**theDocHndl).theGXImageShape, (**theDocHndl).theInkShape);
  572.         SetGWorld((CGrafPtr)theWindow,theGDevHndl);
  573.         InvalRect(&theWindow->portRect);
  574.         SetGWorld(oldPort,theGDevHndl);    
  575.     }
  576.     return error;
  577. }
  578.  
  579.  
  580. /****    Create QDGX type rect    ****/
  581.  
  582. #pragma segment gxGrafix
  583. void    CreateGXRect(gxRectangle* theGXRect, short top, short left, short bottom, short right)
  584. {
  585.     theGXRect->top = ff(top);
  586.     theGXRect->left = ff(left);
  587.     theGXRect->bottom = ff(bottom);
  588.     theGXRect->right = ff(right);
  589. }
  590.  
  591.  
  592. /****    get copy of QDGX transform matrix and save for Undo Operation    ****/
  593.  
  594. #pragma segment gxGrafix
  595. OSErr    SaveTransformCopy(ImageDocHndl theDocHndl, Boolean isUndoOp)
  596. {
  597.     gxTransferMode        theTransform;
  598.     gxTransform            theShapeTransform;
  599.     OSErr                error = noErr;
  600.     
  601.     if (isUndoOp)
  602.     {
  603.         switch ((*theDocHndl)->theGXUndoType)
  604.         {
  605.             case kGXinkTransform:
  606.                 GXGetInkTransfer((**theDocHndl).theInkShape, &(*theDocHndl)->theUndoInkTransform);
  607.             break;
  608.             case kGXshapeTransform:
  609.                 theShapeTransform = GXGetShapeTransform((*theDocHndl)->theGXImageShape);
  610.                 (*theDocHndl)->theUndoShapeTransform = GXCopyToTransform(nil, theShapeTransform);
  611.             break;
  612.         }
  613.     }
  614.     (*theDocHndl)->hasUndoTemp = true;
  615.     (*theDocHndl)->theUndoState = kCanUndo;
  616.     SetUndoItemText((*theDocHndl)->theUndoState);
  617.     return error;
  618. }
  619.  
  620.  
  621. /****    restore QDGX transform matrix for undo Operation    ****/
  622.  
  623. #pragma segment gxGrafix
  624. OSErr    RestoreOldTransformCopy(ImageDocHndl theDocHndl, Boolean isUndoOp)
  625. {
  626.     GrafPtr                oldPort,
  627.                         theWindow;
  628.     gxTransferMode        theTransform;
  629.     gxTransform            theShapeTransform;
  630.     OSErr                error = noErr;
  631.  
  632.     if (isUndoOp)
  633.     {
  634.         switch ((*theDocHndl)->theGXUndoType)
  635.         {
  636.             case kGXinkTransform:
  637.                 GXSetInkTransfer((**theDocHndl).theInkShape, &(*theDocHndl)->theUndoInkTransform);
  638.                 GXSetShapeInk((**theDocHndl).theGXImageShape, (**theDocHndl).theInkShape);
  639.             break;
  640.             case kGXshapeTransform:
  641.                 theShapeTransform = GXGetShapeTransform((*theDocHndl)->theGXImageShape);
  642.                 GXCopyToTransform(theShapeTransform, (*theDocHndl)->theUndoShapeTransform);
  643.                 GXDisposeTransform((*theDocHndl)->theUndoShapeTransform);
  644.             break;
  645.         }
  646.     }
  647.     (*theDocHndl)->theUndoState = kCannotUndo;
  648.     SetUndoItemText((*theDocHndl)->theUndoState);
  649.     GetPort(&oldPort);
  650.     theWindow = FrontWindow();
  651.     SetPort(theWindow);
  652.     InvalRect(&theWindow->portRect);
  653.     SetPort(oldPort);
  654.     return error;
  655. }